package com.sto.stoapp.activity.scanner;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;

import com.sto.stoapp.activity.R;
import com.sto.stoapp.activity.scanner.delete.StoDeleteDetailActivity;
import com.sto.stoapp.adapter.InquiryMenuAdapter;
import com.sto.stoapp.dataprocess.ProcessTableData;
import com.sto.stoapp.entity.InquiryEntity;
import com.sto.stoapp.listener.StoOnItemClickListener;
import com.sto.stoapp.widget.StoHomeActivity;

import java.util.ArrayList;
import java.util.List;

public class StoDeleteWrongScanningActivity extends StoHomeActivity {
	private ListView datalist = null; // 定义ListView组件
	private List<InquiryEntity> list = new ArrayList<InquiryEntity>(); // 定义显示的内容包装
	private InquiryEntity inquiryEntity;
	private ProcessTableData tableData;

	private String busiType = "";

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		super.setContentView(R.layout.sto_inquirymenu_list);
		Bundle extras = getIntent().getExtras();
		busiType = extras.getString("busiType");
		// 业务类型广播
		this.setTitleBottom(R.string.delete_wrong_sanning, busiType);

		tableData = new ProcessTableData();
		initWidget();
	}

	private void initWidget() {
		this.datalist = (ListView) super.findViewById(R.id.dest_list); // 取得组件
		datalist.setOnItemClickListener(new StoOnItemClickListener(this) {
			@Override
			public void KcOnItemClickListener(AdapterView<?> parent, View view,
					int position, long id) {
				Intent intent = new Intent(StoDeleteWrongScanningActivity.this,
						StoDeleteDetailActivity.class);
				// 查询数据项名称
				intent.putExtra("inquiryNameItem",
						tableData.getProcessDeleteData(position, 0));
				// 查询对应表名的序号
				intent.putExtra("inquiryTableItem",
						tableData.getProcessDeleteData(position, 1));
				intent.putExtra("busiType", busiType);
				startActivity(intent);
			}
		});

		displayListView();
	}

	private void displayListView() {
		int maxItem = tableData.getDeleteMaxItem();

		for (int x = 0; x < maxItem; x++) {
			inquiryEntity = new InquiryEntity();
			inquiryEntity.setMenuName(getString(tableData.getProcessDeleteData(
					x, 0)));
			inquiryEntity.setImageId(R.drawable.next);
			this.list.add(inquiryEntity); // 保存了所有的数据行

		}
		InquiryMenuAdapter menuAdapter = new InquiryMenuAdapter(this, list);
		datalist.setAdapter(menuAdapter);
	}


}
